<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册新用户l</title>
    <style>
        h1{ color:red; }
        input{ padding:10px; margin: 5px 0; border-radius: 8px; }
        .msg{ color:red; margin:10px 0; }
    </style>
</head>
<body>
<?php
if($_POST){
    try {
        $db = new PDO("mysql:host=localhost;dbname=db5;", 'root', '12qwas');
        $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        $ps = $db->prepare('insert into students(xh,name,tel) value (?,?,?)');
        $rs = $ps->execute([$_POST['xh'], $_POST['name'], $_POST['tel']]);
        echo "<pre>", print_r($_POST, return: true), "插入记录: $rs</pre>";
    }catch (PDOException $e){
        $msg=$e->getMessage();
    }
}
?>
<h1>注册新用户</h1>
<form method="post" >
    学号：<input name="xh" value="<?= $_POST['xh'] ?>" /><br>
    姓名：<input name="name" value="<?= $_POST['name'] ?>" /><br>
    电话：<input name="tel" value="<?= $_POST['tel'] ?>" /><br>
    <div class="msg"><?= $msg ?></div>
    <input type="submit" value=" 提交数据 ">
</form>
</body>
</html>
